package org.example.controller;

import org.example.dto.Dog;
import org.example.mapper.DogMapper;
import org.example.service.DynamicsSwitchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/dy1")
public class DynamicsSwitch {

    @Autowired
    private DynamicsSwitchService ds;

    //根据参数，动态切换数据源
    @RequestMapping("s")
    public List<Dog> findDogs(@RequestParam String key, HttpServletRequest request){

        System.out.println(key);

        //将需要使用的 key，设置到 session 里边
        request.getSession().setAttribute("dataSourceKey", key);

        return ds.findList();
    }
}
